<template>
    <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <h2 class="text-center  margin-bottom">{{title}}</h2>
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">

                    <a-col :md="8" :sm="24">
                        <a-form-item label="时间" style="display: flex;">
                            <a-range-picker
                                    :placeholder="['开始时间', '结束时间']"
                                    v-model="rangeTime"
                                    format="YYYY-MM-DD"
                                    @change="handleDateChange"
                            />
                        </a-form-item>
                    </a-col>

                    <a-col :md="6" :sm="24">
                        <a-form-item label="机构名称">
                            <a-input v-model="queryParam.customerName" placeholder="机构名称"/>
                        </a-form-item>
                    </a-col>

                    <a-col :md="6" :sm="24">
                        <a-form-item label="预警类型">
                            <a-select placeholder="预警类型" v-model="queryParam.organizationSupervise">
                                <a-select-option value="1">五天未提交预警</a-select-option>
                                <a-select-option value="2">48小时未提交预警</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>

                    <a-col :md="8" :sm="24" v-if="showSelectArea">
                        <a-form-item label="区域查询">
                            <select-area ref="selectAreaRef" @change="changeArea"></select-area>
                        </a-form-item>
                    </a-col>

                </a-row>
            </a-form>
        </div>
        <!-- 查询区域-END -->
        <div class="table-operator" style="display: flex;justify-content: space-between;align-items: center;">
            <div>
                <a-button type="primary" @click="searchQuery" icon="search">查询数据列表</a-button>
                <a-button type="primary" @click="resetForm">重置查询</a-button>
            </div>
            <div>
                <a-button type="primary" icon="printer" v-print="'#printTableList'">打印</a-button>
            </div>
        </div>

        <!-- table区域-begin -->
        <div>
            <a-table
                    ref="table"
                    size="middle"
                    bordered
                    rowKey="id"
                    :columns="columns"
                    :dataSource="dataSource"
                    :pagination="ipagination"
                    :loading="loading"
                    class="j-table-force-nowrap"
                    @change="handleTableChange"
            >
                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="link" slot-scope="text,record">
                    <a href="#" style="color: #3fe4f1;" @click="handleShowDetail(record)">{{text}}</a>
                </template>
                <template slot="imgSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                    <img v-else :src="text" height="25px" alt style="width: auto;height: 50px;"/>
                </template>
            </a-table>
        </div>

        <customer-timeout-log-model ref="customerTimeoutRef" ></customer-timeout-log-model>

        <div v-show="false">
            <div id="printTableList">
                <h2 class="text-center  margin-bottom" v-if="queryParam.organizationSupervise == '2'">
                    二级及二级以上医疗机构 48小时超时未提交机构
                </h2>
                <h2 class="text-center  margin-bottom" v-else>
                    一级及以及以下医疗机构 五天超时未提交机构
                </h2>
                <h3 v-if="rangeTime.length">时间 ： {{rangeTime[0]}} 至 {{rangeTime[1]}}</h3>

                <a-table
                        size="small"
                        bordered
                        rowKey="id"
                        :columns="columns"
                        :dataSource="dataSource"
                        :pagination="false"
                >
                    <template slot="htmlSlot" slot-scope="text">
                        <div style="color: black !important;" v-html="text"></div>
                    </template>
                </a-table>
            </div>
        </div>


    </a-card>
</template>

<script>
    /**
     * create by Jane
     */
    import '@/assets/less/TableExpand.less'
    import { mixinDevice } from '@/utils/mixin'
    import { JeecgListMixin } from '@/mixins/JeecgListMixin'
    import SelectArea from '@/components/Jane/SelectArea'

    import { downloadFile } from '../../../api/manage' // 模糊下拉查询
    import CustomerTimeoutLogModel from './modules/CustomerTimeoutLogModel'

    export default {
        name: 'CustomerTimeoutLog',
        mixins: [JeecgListMixin, mixinDevice],
        components: {
            SelectArea,
            CustomerTimeoutLogModel,
        },
        data() {
            return {
                title: '机构超时提交记录',
                rangeTime: [],
                queryParam: {
                    creatTimeBegin: null,
                    creatTimeEnd: null,
                    // 1 五天未提交（一级及一级以下医疗机构）   2 重点监管（二级及二级以上医疗机构）
                    organizationSupervise: '1'
                },
                // 表头
                columns: [],
                url: {
                    list: '/hc/hcRecycleSubmitWarning/list',
                    exportXlsUrlOkForImages: '#'
                },
                showDetail: false
            }
        },
        mounted() {
        },
        computed: {
            showSelectArea: function() {
                let state = true
                let userInfo = this.$store.getters.userInfo
                if (userInfo.provinceCode && userInfo.cityCode && userInfo.areaCode) {
                    state = false
                }
                return state
            }
        },
        methods: {
            // 配置默认信息
            initConfig: function() {
                this.queryParam.creatTimeBegin = new Date().MonthFirstDay();
                this.queryParam.creatTimeEnd = new Date().MonthLastDay();
                this.rangeTime = [this.queryParam.creatTimeBegin, this.queryParam.creatTimeEnd];
                this.queryParam.organizationSupervise = '1';
                this.queryParam.customerName = '';
                this.queryParam.cityCode = '';
                this.queryParam.areaCode = '';

                // 获取到用户登陆的信息
                let userInfo = this.$store.getters.userInfo
                if (userInfo.cityCode) {
                    this.queryParam.cityCode = userInfo.cityCode
                }
                if (userInfo.areaCode) {
                    this.queryParam.areaCode = userInfo.areaCode
                }

                let ref = this.$refs.selectAreaRef;
                if(ref && ref.clearSelectArea != undefined){
                    ref.clearSelectArea();
                }
            },
            // 初始化配置信息
            async initDictConfig() {
                this.initConfig()
                this.setColumns()
            },
            // 重置筛选表单
            resetForm: function() {
                this.initConfig()
                this.searchQuery()
            },
            handleDateChange(value, dateString) {
                this.rangeTime = dateString
                if (dateString[0]) {
                    this.queryParam.creatTimeBegin = dateString[0]
                }
                if (dateString[1]) {
                    this.queryParam.creatTimeEnd = dateString[1]
                }
            },
            // 设置表格头部信息
            setColumns() {
                this.columns = [
                    {
                        title: '序号',
                        dataIndex: 'id',
                        key: 'rowIndex',
                        width: 60,
                        align: 'center',
                        customRender: (text, row, index) => {
                            return parseInt(index) + 1
                        }
                    },
                    // {
                    //     title: '机构编码',
                    //     dataIndex: 'customerNumber',
                    //     key: 'customerNumber'
                    // },
                    {
                        title: '机构名称',
                        dataIndex: 'customerName',
                        key: 'customerName',
                        scopedSlots: { customRender: 'link' }
                    },
                    {
                        title: '负责人',
                        dataIndex: 'leadername',
                        key: 'leadername'
                    },
                    {
                        title: '联系电话',
                        dataIndex: 'leaderphone',
                        key: 'leaderphone'
                    },
                    {
                        title: '总计未提交次数',
                        align: 'center',
                        dataIndex: 'num',
                        scopedSlots: { customRender: 'htmlSlot' },
                        customRender: function(value, row, index) {
                            const obj = {
                                children: < span
                            style = 'color:orange;font-size:16px;font-weight:bold;' > { value } < /span>,
                            attrs: {
                            }
                        }
                            return obj
                        }
                    },
                    {
                        title: '最后提交时间',
                        align: 'center',
                        dataIndex: 'lastSubmitTime'
                    },
                    {
                        title: '所在地址',
                        dataIndex: 'province',
                        key: 'province',
                        customRender: (text, row, index) => {
                            return `${row.province || ''}${row.city || ''}${row.area || ''}${row.address || ''}`
                        }
                    }
                ]
            },
            async changeArea({ area, city }) {
                if (city) {
                    this.queryParam.cityCode = city
                }
                if (area) {
                    this.queryParam.areaCode = area
                }
            },
            searchQuery: function() {
                this.loadData(1)
            },
            handleMwExportXlsForImages() {
                let param = { ...this.queryParam }
                let name = `各机构台账统计-${new Date().FormatDate()}.xls`
                downloadFile(this.url.exportXlsUrlOkForImages, name, param)
            },
            // 根据机构编号查询机构超时提交信息详情
            handleShowDetail : function(row) {
                let ref = this.$refs.customerTimeoutRef;
                if(ref){
                    ref.show(row,this.rangeTime);
                }
            },
        }
    }
</script>
<style scoped>
    @import '~@assets/less/common.less';
</style>
